package util

import (
	"fmt"
	"time"
)

func GetSecond(hours, minu, second int) int {
	return hours*3600 + minu*60 + second
}

func GetCurrnetSecond() int {
	now := time.Now()
	seconds := now.Sub(time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())).Seconds()
	return int(seconds)
}

func CompareTimeSecond(uptime, lowtime int) bool {
	second := GetCurrnetSecond()
	if second <= uptime && second >= lowtime {
		return true
	}
	return false
}

func GetTimeSecond(timeStr string) int {
	parse, err := time.Parse(time.TimeOnly, timeStr)
	if err != nil {
		fmt.Println(err)
	}
	second := GetSecond(parse.Hour(), parse.Minute(), parse.Second())
	return second
}

func CompareDate(up, low time.Time) string {
	if up.After(low) {
		return ">"
	} else if up.Before(low) {
		return "<"
	}
	return "="
}

func CompareDateInterval(upDate, lowDate string) bool {
	now := time.Now()
	up, err := time.Parse(time.DateOnly, upDate)
	low, err := time.Parse(time.DateOnly, lowDate)
	if err != nil {
		return false
	}
	now1, err := time.Parse(time.DateOnly, now.Format(time.DateOnly))
	val1 := CompareDate(up, now1)
	val2 := CompareDate(low, now1)
	switch val1 {
	case "=", ">":
		switch val2 {
		case "=", "<":
			fmt.Println("符合要求")
			return true
		}
	}
	return false
}
